﻿<%@ Page Title="My Samples" Language="C#" MasterPageFile="~/MasterPage.master"
     AutoEventWireup="true" CodeFile="MySamples.aspx.cs" Inherits="MySamples" %>

<%-- Custom made page for screwturn wiki --%>
<asp:Content ID="Content1" ContentPlaceHolderID="CphMaster" runat="Server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
     </asp:ScriptManager>
     <asp:UpdatePanel ID="SampleToolsUpdatePanel" runat="server">
          <ContentTemplate>
               <h1 class="pagetitlesystem">
                    <asp:Literal ID="lblTitle" runat="server" meta:resourcekey="lblTitleResource1"
                         Text="My Samples" /></h1>
               <asp:MultiView ID="SampleTools" runat="server" ActiveViewIndex="0">
                    <asp:View runat="server">
                         <asp:Button runat="server" Text="Add" OnClick="AddSampleButton_Click" />
                         <hr />
                         <asp:GridView ID="SamplesTableGridView" runat="server" AllowPaging="True"
                              AllowSorting="True" AutoGenerateColumns="False" BackColor="White"
                              BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
                              DataKeyNames="Id" CellPadding="3" DataSourceID="SamplesDataSource"
                              GridLines="Horizontal" OnRowCommand="SamplesTableGv_RowCommand"
                              Width="100%" EmptyDataText="You don't have any Samples added yet.">
                              <RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
                              <Columns>
                                   <asp:ButtonField ButtonType="Link" DataTextField="Name" HeaderText="Name"
                                        SortExpression="Name" CausesValidation="false" CommandName="showSelectedSampleInfo"
                                        ShowHeader="True">
                                        <ItemStyle Width="100px" VerticalAlign="Top" />
                                   </asp:ButtonField>
                                   <asp:BoundField DataField="Buffer" HeaderText="Buffer" SortExpression="Buffer">
                                        <ItemStyle Width="150px" VerticalAlign="Top" />
                                   </asp:BoundField>
                                   <asp:BoundField DataField="Labeling" HeaderText="Labeling" SortExpression="Labeling">
                                        <ItemStyle Width="100px" VerticalAlign="Top" />
                                   </asp:BoundField>
                                   <asp:BoundField DataField="Short Description" HeaderText="Short Description"
                                        SortExpression="Short Description">
                                        <ItemStyle VerticalAlign="Top" />
                                   </asp:BoundField>
                                   <asp:TemplateField HeaderText="Contact" SortExpression="Contact">
                                        <ItemTemplate>
                                             <asp:HyperLink runat="server" Text='<%# Eval("Contact") %>' NavigateUrl='<%# Eval("Email", "mailto://{0}") %>'
                                                  ID="hlEmail" />
                                        </ItemTemplate>
                                        <ItemStyle Width="200px" VerticalAlign="Top" Font-Underline="true" />
                                   </asp:TemplateField>
                                   <asp:BoundField DataField="Datum" DataFormatString="{0:d}" HeaderText="Datum"
                                        SortExpression="Datum">
                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" Width="100px" />
                                   </asp:BoundField>
                                   <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False"
                                        SortExpression="Id" Visible="False" />
                              </Columns>
                              <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
                              <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
                              <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
                              <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" HorizontalAlign="Left" />
                              <AlternatingRowStyle BackColor="#F7F7F7" />
                         </asp:GridView>
                         <asp:SqlDataSource ID="SamplesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:NMRUserDataConnectionString %>"
                              SelectCommand="SELECT s1.id, s1.name AS Name, s1.buffer AS Buffer, s1.labeling AS Labeling, s1.memo AS [Short Description], s1.contact AS Contact, s1.contactmail AS Email, s1.date AS Datum, s1.version, s1.versioninfo FROM (SELECT s2.name, MAX(s2.version) AS MaxVersion FROM samples AS s2 INNER JOIN relation_samples_to_users AS rsu ON s2.id = rsu.sampleid WHERE (rsu.username = @username) GROUP BY s2.name) AS x INNER JOIN samples AS s1 ON s1.name = x.name AND s1.version = x.MaxVersion INNER JOIN relation_samples_to_users AS rsu ON s1.id = rsu.sampleid WHERE (rsu.username = @username)">
                              <SelectParameters>
                                   <asp:Parameter Name="username" Type="String" DefaultValue="none" />
                              </SelectParameters>
                         </asp:SqlDataSource>
                         <hr />
                         <asp:Button runat="server" Text="Add" OnClick="AddSampleButton_Click" />
                    </asp:View>
                    <asp:View runat="server">
                         <asp:Label ID="lblName" runat="server" Text="Name" Width="150px"></asp:Label>
                         <asp:TextBox ID="tbName" runat="server" Columns="80" Width="550px"
                              Font-Size="14px" CssClass="InputField"></asp:TextBox>
                         <asp:RequiredFieldValidator ID="valReqFieldName" runat="server"
                              ControlToValidate="tbName" Display="Dynamic" ErrorMessage="Name Must Be Present."
                              SetFocusOnError="True"></asp:RequiredFieldValidator>
                         <asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                              runat="server" ControlToValidate="tbName" Display="Dynamic"
                              ErrorMessage="Name must contain only Letters and Spaces."
                              ValidationExpression="[A-z0-9][0-9A-z\s]+" SetFocusOnError="True"></asp:RegularExpressionValidator>
                         <asp:CustomValidator ID="UniqueNamecv" runat="server" ControlToValidate="tbName"
                              Display="Dynamic" EnableClientScript="False" ErrorMessage="Sample with this name already exists."
                              OnServerValidate="UniqueNameValidate"></asp:CustomValidator>
                         <br />
                         <br />
                         <asp:Label ID="lblBuffer" runat="server" Text="Buffer" Width="150px"></asp:Label>
                         <asp:TextBox ID="tbBuffer" runat="server" Columns="80" Width="550px"
                              Font-Size="14px" CssClass="InputField"></asp:TextBox>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                              ControlToValidate="tbBuffer" Display="Dynamic" ErrorMessage="Buffer Must Be Specified"></asp:RequiredFieldValidator>
                         <asp:RegularExpressionValidator ID="RegularExpressionValidator2"
                              runat="server" ControlToValidate="tbBuffer" Display="Dynamic"
                              ErrorMessage="Buffer can only contain letters, numbers and spaces."
                              ValidationExpression="[A-z0-9][A-z0-9\s,./()\+\-]+"></asp:RegularExpressionValidator>
                         <br />
                         <br />
                         <asp:Label ID="lblLabeling" runat="server" Text="Labeling" Width="150px"></asp:Label>
                         <asp:TextBox ID="tbLabeling" runat="server" Width="550px" CssClass="InputField">Unlabeled</asp:TextBox>
                         <asp:RegularExpressionValidator ID="RegularExpressionValidator7"
                              runat="server" ControlToValidate="tbLabeling" ErrorMessage="Isotope names separated by semicolumns."
                              ValidationExpression="Unlabeled|((15N|13C|2H|31P)(;|15N|13C|2H|31P|\s*)*)"></asp:RegularExpressionValidator>
                         <br />
                         <br />
                         <asp:Label ID="lblMemo" runat="server" Text="Short Description"
                              Width="150px" Style="vertical-align: top"></asp:Label>
                         <asp:TextBox ID="tbMemo" CssClass="InputField" runat="server"
                              MaxLength="2000" Rows="2" TextMode="MultiLine" Width="550px"
                              Font-Size="14px"></asp:TextBox>
                         <asp:RegularExpressionValidator ID="RegularExpressionValidator3"
                              Style="vertical-align: top" runat="server" ControlToValidate="tbMemo"
                              Display="Dynamic" ErrorMessage="Short Description Should Not Contain &lt;&gt; Charachters."
                              ValidationExpression="[A-z0-9\s\\/:.,?!@#$;%^&amp;*()\\]*"></asp:RegularExpressionValidator>
                         <br />
                         <br />
                         <asp:Panel runat="server" ID="UpdateInfopn" Style="display: none">
                              <asp:Label ID="lblVersionInfo" runat="server" Text="Version Specific Note"
                                   Width="150px" Style="vertical-align: top"></asp:Label>
                              <asp:TextBox Font-Size="14px" ID="tbVersionInfo" CssClass="InputField"
                                   runat="server" MaxLength="2000" Rows="2" TextMode="MultiLine"
                                   Width="550px"></asp:TextBox>
                              <asp:RegularExpressionValidator ID="RegularExpressionValidator5"
                                   Style="vertical-align: top" runat="server" ControlToValidate="tbVersionInfo"
                                   Display="Dynamic" ErrorMessage="Version Info Should Not Contain &lt;&gt; Charachters."
                                   ValidationExpression="[A-z0-9\s\\/:.,?!@#$;%^&amp;*()\\]*"></asp:RegularExpressionValidator>
                              <br />
                              <br />
                         </asp:Panel>
                         <asp:Label ID="lblContact" runat="server" Text="Contact Person"
                              Width="150px"></asp:Label>
                         <asp:TextBox ID="tbContactPerson" runat="server" Columns="80"
                              Font-Size="14px" CssClass="InputField" Width="550px"></asp:TextBox>
                         <br />
                         <br />
                         <asp:Label ID="lblContactEmail" runat="server" Text="Contact Email"
                              Width="150px"></asp:Label>
                         <asp:TextBox ID="tbContactEmail" runat="server" Columns="80"
                              Font-Size="14px" CssClass="InputField" Width="550px"></asp:TextBox>
                         <asp:RegularExpressionValidator ID="RegularExpressionValidator6"
                              runat="server" ControlToValidate="tbContactEmail" Display="Dynamic"
                              ErrorMessage="Email is not correct." ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                         <br />
                         <br />
                         <asp:Label ID="lblContent" runat="server" Text="Content" Width="150px"
                              Style="vertical-align: top"></asp:Label>
                         <asp:TextBox ID="tbContent" runat="server" MaxLength="50000"
                              CssClass="InputField" Font-Size="14px" Rows="20" TextMode="MultiLine"
                              Width="550px"></asp:TextBox>
                         <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="tbContent"
                              Style="vertical-align: top" EnableClientScript="False" ErrorMessage="Scripts Are Not Allowed."
                              OnServerValidate="ValidateForScripts" ValidateEmptyText="True"
                              Display="Dynamic"></asp:CustomValidator>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                              Style="vertical-align: top" ControlToValidate="tbContent"
                              Display="Dynamic" ErrorMessage="Content must present."></asp:RequiredFieldValidator>
                         <br />
                         <br />
                         <asp:Button ID="butSubmit" runat="server" Text="Submit" OnCommand="butSubmit_Command" />
                         <asp:Button ID="butClear" runat="server" CausesValidation="False"
                              OnClick="butClear_Click" Text="Clear" />
                    </asp:View>
                    <asp:View runat="server">
                         <p class="Boxy">
                              <asp:Label runat="server" ID="lblDate2"></asp:Label>
                         </p>
                         <p class="Boxy">
                              <asp:Label runat="server" ID="lblBuffer2"></asp:Label>
                         </p>
                         <p class="Boxy">
                              <asp:Label runat="server" ID="lblLabeling2"></asp:Label>
                         </p>
                         <p class="Boxy">
                              <asp:Label runat="server" ID="lblMemo2"></asp:Label>
                         </p>
                         <p class="Boxy">
                              <asp:Label runat="server" ID="lblContact2"></asp:Label></p>
                         <div style="margin: 0px 40px 0px 5px">
                              <asp:Panel runat="server" CssClass="ContentBox">
                                   Content:
                                   <br />
                                   <asp:TextBox ID="tbContent2" Rows="40" runat="server" Wrap="false"
                                        CssClass="ContentText" TextMode="MultiLine" ReadOnly="true">
                                   </asp:TextBox>
                              </asp:Panel>
                              <asp:Panel ID="panPreviousVersions" CssClass="VersionsBox" runat="server">
                                   <asp:Label ID="Label1" runat="server" Text="<p><b>Versions:</b></p>"></asp:Label>
                                   <asp:ListView ID="ListView1" runat="server" DataSourceID="PrevVersionsSQLDatasource"
                                        DataKeyNames="SampleID">
                                        <ItemTemplate>
                                             <li style="background-color: #DCDCDC; color: #000000;">
                                                  <asp:LinkButton ID="VersionLinkButton" CommandArgument='<%# Eval("SampleID") %>'
                                                       CommandName="ShowSampleInfoWithID" runat="server" OnCommand="VersionLinkButton_Click">
                                         Version: <%# Eval("Version") %>
                                                  </asp:LinkButton>
                                                  created on <b>
                                                       <asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' /></b>.
                                                  <br />
                                                  <asp:Label ID="InfoLabel" runat="server" Text='<%# Eval("Info") %>' />
                                                  <br />
                                             </li>
                                        </ItemTemplate>
                                        <AlternatingItemTemplate>
                                             <li style="background-color: #CEE0E3; color: Black">
                                                  <asp:LinkButton ID="VersionLinkButton" CommandArgument='<%# Eval("SampleID") %>'
                                                       CommandName="ShowSampleInfoWithID" runat="server" OnCommand="VersionLinkButton_Click">
                                         Version: <%# Eval("Version") %>
                                                  </asp:LinkButton>
                                                  created on <b>
                                                       <asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' /></b>.
                                                  <br />
                                                  <asp:Label ID="InfoLabel" runat="server" Text='<%# Eval("Info") %>' />
                                                  <br />
                                             </li>
                                        </AlternatingItemTemplate>
                                        <EmptyDataTemplate>
                                             There is no previous versions for this experiment.
                                        </EmptyDataTemplate>
                                        <InsertItemTemplate>
                                             <li style="">Version:
                                                  <asp:TextBox ID="VersionTextBox" runat="server" Text='<%# Bind("Version") %>' />
                                                  <br />
                                                  Date:
                                                  <asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>' />
                                                  <br />
                                                  Info:
                                                  <asp:TextBox ID="InfoTextBox" runat="server" Text='<%# Bind("Info") %>' />
                                                  <br />
                                                  <asp:Button ID="InsertButton" runat="server" CommandName="Insert"
                                                       Text="Insert" />
                                                  <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                                                       Text="Clear" />
                                             </li>
                                        </InsertItemTemplate>
                                        <LayoutTemplate>
                                             <ul id="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;">
                                                  <li id="itemPlaceholder" runat="server" />
                                             </ul>
                                             <div style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                                                  color: #000000;">
                                             </div>
                                        </LayoutTemplate>
                                        <EditItemTemplate>
                                             <li style="background-color: #008A8C; color: #FFFFFF;">SpecID:
                                                  <asp:Label ID="SpecIDLabel1" runat="server" Text='<%# Eval("SampleID") %>' />
                                                  <br />
                                                  Version:
                                                  <asp:TextBox ID="VersionTextBox" runat="server" Text='<%# Bind("Version") %>' />
                                                  <br />
                                                  Date:
                                                  <asp:TextBox ID="DateTextBox" runat="server" Text='<%# Bind("Date") %>' />
                                                  <br />
                                                  Info:
                                                  <asp:TextBox ID="InfoTextBox" runat="server" Text='<%# Bind("Info") %>' />
                                                  <br />
                                                  <asp:Button ID="UpdateButton" runat="server" CommandName="Update"
                                                       Text="Update" />
                                                  <asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
                                                       Text="Cancel" />
                                             </li>
                                        </EditItemTemplate>
                                        <ItemSeparatorTemplate>
                                             <br />
                                        </ItemSeparatorTemplate>
                                        <SelectedItemTemplate>
                                             <li style="background-color: #008A8C; font-weight: bold; color: #FFFFFF;">
                                                  SpecID:
                                                  <asp:Label ID="SpecIDLabel" runat="server" Text='<%# Eval("SampleID") %>' />
                                                  <br />
                                                  Version:
                                                  <asp:Label ID="VersionLabel" runat="server" Text='<%# Eval("Version") %>' />
                                                  <br />
                                                  Date:
                                                  <asp:Label ID="DateLabel" runat="server" Text='<%# Eval("Date") %>' />
                                                  <br />
                                                  Info:
                                                  <asp:Label ID="InfoLabel" runat="server" Text='<%# Eval("Info") %>' />
                                                  <br />
                                             </li>
                                        </SelectedItemTemplate>
                                   </asp:ListView>
                              </asp:Panel>
                         </div>
                         <asp:SqlDataSource ID="PrevVersionsSQLDatasource" runat="server"
                              ConnectionString="<%$ ConnectionStrings:NMRUserDataConnectionString %>"
                              SelectCommand="SELECT samples.id AS SampleID, samples.version AS Version, samples.date AS Date, samples.versioninfo AS Info FROM relation_samples_to_users INNER JOIN samples ON relation_samples_to_users.sampleid = samples.id WHERE (relation_samples_to_users.username = @username) AND (samples.name = (SELECT name FROM samples AS samples_1 WHERE (id = @id))) ORDER BY Version DESC">
                              <SelectParameters>
                                   <asp:Parameter Name="username" Type="String" DefaultValue="none" />
                                   <asp:Parameter Name="Id" DefaultValue="5" />
                              </SelectParameters>
                         </asp:SqlDataSource>
                         <asp:Panel ID="Panel1" runat="server" Style="clear: both" />
                         <hr />
                         <asp:Button ID="btnUpdate2" runat="server" Text="Update" CommandArgument="none"
                              OnCommand="btnUpdate2_Command" />
                         <asp:Button ID="btnDelete2" runat="server" Text="Delete" OnClick="btnDelete2_Click" />
                         <span id="Span1" runat="server" style="text-align: right">
                              <asp:Label runat="server" ID="lblDeleteQuestion" Text="Really Delete?"
                                   Visible="false"></asp:Label>
                              <asp:Button ID="btnCancelDelete2" runat="server" Text="Cancel"
                                   Visible="false" OnClick="btnCancelDelete2_Click" />
                              <asp:Button ID="btnRealyDelete2" runat="server" Text="Confirm Delete"
                                   Visible="false" CommandArgument="none" CommandName="Delete"
                                   OnCommand="btnRealyDelete2_Command" />
                         </span>
                    </asp:View>
               </asp:MultiView>
          </ContentTemplate>
          <Triggers>
          </Triggers>
     </asp:UpdatePanel>
</asp:Content>
